/*
 * Copyright 2010 Michael Nitsche
 *
 * This program is free software: you can redistribute it and/or modify
 * it under the terms of the GNU Lesser General Public License as published by
 * the Free Software Foundation, either version 3 of the License, or
 * (at your option) any later version.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU Lesser General Public License for more details.
 *
 * You should have received a copy of the GNU Lesser General Public License
 * along with this program.  If not, see <http://www.gnu.org/licenses/>.
 */

package de.mnit.basis.daten.struktur;

import java.util.LinkedList;

/**
 * @author Michael Nitsche
 */
public class Warteschlange<T> {

	private final LinkedList<T> schlange;


	public static <T> Warteschlange<T> neu()               { return new Warteschlange<T>(); }
	public static <T> Warteschlange<T> neu(Class<T> c)     { return new Warteschlange<T>(); }
	public static <T> Warteschlange<T> neu(T... objekte) {
		Warteschlange<T> erg = neu();
		for(T o : objekte)
			erg.plus(o);
		return erg;
	}


	public Warteschlange() {
		this.schlange=new LinkedList<T>();
	}


	public int gLaenge() {
		return schlange.size();
	}

	public boolean gLeer() {
		return schlange.isEmpty();
	}

	public boolean gGefuellt() {
		return !schlange.isEmpty();
	}

//	public T minus() {
//		return null;
//	}

	public void plus(T t) {
	    schlange.addLast(t);
	}

	public synchronized T gNaechstes() {
	    return gLeer() ? null : schlange.removeFirst();
	}
}
